<!Doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>MySQL 函数 | 菜鸟教程</title>

  <meta name='robots' content='max-image-preview:large' />
<link rel='stylesheet' id='classic-theme-styles-css' href='../0/classic-themes.min.css?ver=6.2' type='text/css' media='all' />
<link rel="canonical" href="../mysql/mysql-functions.html" />
<meta name="keywords" content="MySQL 函数">
<meta name="description" content="MySQL 函数  MySQL 有很多内置的函数，以下列出了这些函数的说明。  MySQL 字符串函数    函数 描述 实例   ASCII(s) 返回字符串 s 的第一个字符的 ASCII 码。  返回 CustomerName 字段第一个字母的 ASCII 码： SELECT ASCII(CustomerName) AS NumCodeOfFirstChar FROM Customers;   CHAR_LENGTH(s) 返回字..">
		
	<link rel="shortcut icon" href="https://static.runoob.com/images/favicon.ico">
	<link rel="stylesheet" href="../0/style.css?v=1.170" type="text/css" media="all" />	
	<link rel="stylesheet" href="../0/font-awesome.min.css" media="all" />	
  <!--[if gte IE 9]><!-->
  <script src=""></script>
  <!--<![endif]-->
  <!--[if lt IE 9]>
     <script src=""></script>
     <script src=""></script>
  <![endif]-->
  <link rel="apple-touch-icon" href="https://static.runoob.com/images/icon/mobile-icon.png"/>
  <meta name="apple-mobile-web-app-title" content="菜鸟教程">
</head>
<body>

<!--  头部 -->
<div class="container logo-search">

  <div class="col search row-search-mobile">
    <form action="index.php">
      <input class="placeholder" placeholder="搜索……" name="s" autocomplete="off">
      
    </form>
  </div>

  <div class="row">
    <div class="col logo">
      <h1><a href="../">菜鸟教程 -- 学的不仅是技术，更是梦想！</a></h1>
    </div>
        <div class="col right-list"> 
    <button class="btn btn-responsive-nav btn-inverse" data-toggle="collapse" data-target=".nav-main-collapse" id="pull" style=""> <i class="fa fa-navicon"></i> </button>
    </div>
        
    <div class="col search search-desktop last">
      <div class="search-input" >
      <form action="//www.runoob.com/" target="_blank">
        <input class="placeholder" id="s" name="s" placeholder="搜索……"  autocomplete="off" style="height: 44px;">
      </form>
      
      </div>
    </div>
  </div>
</div>



<!-- 导航栏 -->
<!-- 导航栏 -->
<div class="container navigation">
	<div class="row">
		<div class="col nav">
			<ul class="pc-nav" id="runoob-detail-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JavaScript</a></li>
				<li><a href="javascript:void(0);" data-id="vue">Vue</a></li>
				<li><a href="javascript:void(0);" data-id="bootstrap">Bootstrap</a></li>
				<li><a href="../nodejs/nodejs-tutorial.html">NodeJS</a></li>
				<li><a href="../python3/python3-tutorial.html">Python3</a></li>
				<li><a href="../python/python-tutorial.html">Python2</a></li>
				<li><a href="../java/java-tutorial.html">Java</a></li>
				<li><a href="../cprogramming/c-tutorial.html">C</a></li>
				<li><a href="../cplusplus/cpp-tutorial.html">C++</a></li>
				<li><a href="../csharp/csharp-tutorial.html">C#</a></li>
				<li><a href="../go/go-tutorial.html">Go</a></li>
				<li><a href="../sql/sql-tutorial.html">SQL</a></li>
				<li><a href="../linux/linux-tutorial.html">Linux</a></li>
				<li><a href="../jquery/jquery-tutorial.html">jQuery</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<!--
			
				<li><a href="../w3cnote/knowledge-start.html" style="font-weight: bold;" onclick="_hmt.push(['_trackEvent', '星球', 'click', 'start'])" title="我的圈子">我的圈子</a></li>				
				<li><a href="javascript:;" class="runoob-pop">登录</a></li>
				-->
      		</ul>
			<ul class="mobile-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JS</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<li><a href="javascript:void(0)" class="search-reveal">Search</a> </li>
			</ul>
			
		</div>
	</div>
</div>

<div class="container sub-navigation sub-navigation-articles" style="display:none">
	<div class="row">
		<div class="col nav-sub">
		<ul id="python">
			<li class="cat-item"><a href="../python3/python3-tutorial.html">Python3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../python/python-tutorial.html">Python2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		<ul id="vue">
			<li class="cat-item"><a href="../vue3/vue3-tutorial.html">Vue3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../vue/vue-tutorial.html">vue2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>

		<ul id="bootstrap">
			<li class="cat-item"><a href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap/bootstrap-v2-tutorial.html">Bootstrap2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		</div>
	</div>
</div><!--  内容  -->
<div class="container main">
	<!-- 中间 -->
	<div class="row">
	
<div class="runoob-col-md2">
<div class="left-column">
	<div class="tab" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
	<i class="fa fa-list" aria-hidden="true"></i> 
	<span>MySQL 教程</span>
	<a data-cate="57" href="javascript:void(0);" title="夜间模式"  id="moon"><i class="fa fa-moon-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;"></i></a>
	<a data-cate="57" style="display:none;" href="javascript:void(0);" title="日间模式"  id="sun" ><i class="fa fa-sun-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;line-height: 28px;
}"></i></a>

	</div>
	<div class="sidebar-box gallery-list">
		<div class="design" id="leftcolumn">
						<a target="_top" title="MySQL 教程"  href="../mysql/mysql-tutorial.html" >
			MySQL 教程			</a>
						<a target="_top" title="MySQL 安装"  href="../mysql/mysql-install.html" >
			MySQL 安装			</a>
						<a target="_top" title="MySQL 管理"  href="../mysql/mysql-administration.html" >
			MySQL 管理			</a>
						<a target="_top" title="MySQL PHP 语法"  href="../mysql/mysql-php-syntax.html" >
			MySQL PHP 语法			</a>
						<a target="_top" title="MySQL 连接"  href="../mysql/mysql-connection.html" >
			MySQL 连接			</a>
						<a target="_top" title="MySQL 创建数据库"  href="../mysql/mysql-create-database.html" >
			MySQL 创建数据库			</a>
						<a target="_top" title="MySQL 删除数据库"  href="../mysql/mysql-drop-database.html" >
			MySQL 删除数据库			</a>
						<a target="_top" title="MySQL 选择数据库"  href="../mysql/mysql-select-database.html" >
			MySQL 选择数据库			</a>
						<a target="_top" title="MySQL 数据类型"  href="../mysql/mysql-data-types.html" >
			MySQL 数据类型			</a>
						<a target="_top" title="MySQL 创建数据表"  href="../mysql/mysql-create-tables.html" >
			MySQL 创建数据表			</a>
						<a target="_top" title="MySQL 删除数据表"  href="../mysql/mysql-drop-tables.html" >
			MySQL 删除数据表			</a>
						<a target="_top" title="MySQL 插入数据"  href="../mysql/mysql-insert-query.html" >
			MySQL 插入数据			</a>
						<a target="_top" title="MySQL 查询数据"  href="../mysql/mysql-select-query.html" >
			MySQL 查询数据			</a>
						<a target="_top" title="MySQL WHERE 子句"  href="../mysql/mysql-where-clause.html" >
			MySQL WHERE 子句			</a>
						<a target="_top" title="MySQL UPDATE 更新"  href="../mysql/mysql-update-query.html" >
			MySQL UPDATE 更新			</a>
						<a target="_top" title="MySQL DELETE 语句"  href="../mysql/mysql-delete-query.html" >
			MySQL DELETE 语句			</a>
						<a target="_top" title="MySQL LIKE 子句"  href="../mysql/mysql-like-clause.html" >
			MySQL LIKE 子句			</a>
			<a target="_top" title="MySQL UNION 语句" href="../mysql/mysql-union-operation.html">
			MySQL UNION		</a>			<a target="_top" title="MySQL 排序"  href="../mysql/mysql-order-by.html" >
			MySQL 排序			</a>
			<a target="_top" title="MySQL Group by 语句" href="mysql-group-by-statement.html"> MySQL 分组 </a>			<a target="_top" title="MySQL 连接的使用"  href="../mysql/mysql-join.html" >
			MySQL 连接的使用			</a>
						<a target="_top" title="MySQL NULL 值处理"  href="../mysql/mysql-null.html" >
			MySQL NULL 值处理			</a>
						<a target="_top" title="MySQL 正则表达式"  href="../mysql/mysql-regexp.html" >
			MySQL 正则表达式			</a>
						<a target="_top" title="MySQL 事务"  href="../mysql/mysql-transaction.html" >
			MySQL 事务			</a>
						<a target="_top" title="MySQL ALTER命令"  href="../mysql/mysql-alter.html" >
			MySQL ALTER命令			</a>
						<a target="_top" title="MySQL 索引"  href="../mysql/mysql-index.html" >
			MySQL 索引			</a>
						<a target="_top" title="MySQL 临时表"  href="../mysql/mysql-temporary-tables.html" >
			MySQL 临时表			</a>
						<a target="_top" title="MySQL 复制表"  href="../mysql/mysql-clone-tables.html" >
			MySQL 复制表			</a>
						<a target="_top" title="MySQL 元数据"  href="../mysql/mysql-database-info.html" >
			MySQL 元数据			</a>
						<a target="_top" title="MySQL 序列使用"  href="../mysql/mysql-using-sequences.html" >
			MySQL 序列使用			</a>
						<a target="_top" title="MySQL 处理重复数据"  href="../mysql/mysql-handling-duplicates.html" >
			MySQL 处理重复数据			</a>
						<a target="_top" title="MySQL 及 SQL 注入"  href="../mysql/mysql-sql-injection.html" >
			MySQL 及 SQL 注入			</a>
						<a target="_top" title="MySQL 导出数据"  href="../mysql/mysql-database-export.html" >
			MySQL 导出数据			</a>
						<a target="_top" title="MySQL 导入数据"  href="../mysql/mysql-database-import.html" >
			MySQL 导入数据			</a>
						<a target="_top" title="MySQL 函数"  href="../mysql/mysql-functions.html" >
			MySQL 函数			</a>
						<a target="_top" title="MySQL 运算符"  href="../mysql/mysql-operator.html" >
			MySQL 运算符			</a>
				
		</div>
	</div>	
</div>
</div>	<div class="col middle-column">
		
	
	<div class="article">
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../mysql/mysql-union-operation.html" rel="prev"> MySQL UNION 操作符</a> </div>
			<div class="next-design-link"><a href="../mysql/mysql-func-ifnull.html" rel="next"> MySQL IFNULL() 函数</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
<div class="article-heading-ad" style="display: block;">
<script async src=""
     crossorigin="anonymous"></script>
<!-- 728*90 固定 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="2147566827"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
		<div class="article-body">
		
			<div class="article-intro" id="content">
			
			<h1>MySQL 函数
</h1>
<p>MySQL 有很多内置的函数，以下列出了这些函数的说明。</p>
<hr>
<h2>MySQL 字符串函数</h2>

<table class="reference">
<tbody><tr>
<th style="width:12%">函数</th>
<th>描述</th>
<th>实例</th>
</tr>
<tr>
<td>ASCII(s)</td>
<td>返回字符串 s 的第一个字符的 ASCII 码。</td>
<td>
<p>返回 CustomerName 字段第一个字母的 ASCII 码：</p>
<pre>SELECT ASCII(CustomerName) AS NumCodeOfFirstChar
FROM Customers;</pre></td>
</tr>
<tr>
<td>CHAR_LENGTH(s)</td>
<td>返回字符串 s 的字符数</td>
<td>
<p>返回字符串 RUNOOB 的字符数</p>
<pre>
SELECT CHAR_LENGTH("RUNOOB") AS LengthOfString;
</pre>
</td>
</tr>
<tr>
<td>CHARACTER_LENGTH(s)</td>
<td>返回字符串 s 的字符数，等同于 CHAR_LENGTH(s)</td>
<td>
<p>返回字符串 RUNOOB 的字符数</p>
<pre>
SELECT CHARACTER_LENGTH("RUNOOB") AS LengthOfString;
</pre>
</td>
</tr>
<tr>
<td>CONCAT(s1,s2...sn)</td>
<td>字符串 s1,s2 等多个字符串合并为一个字符串</td>
<td>
<p>合并多个字符串</p>
<pre>
SELECT CONCAT("SQL ", "Runoob ", "Gooogle ", "Facebook") AS ConcatenatedString;
</pre>
</td>
</tr>
<tr>
<td>CONCAT_WS(x, s1,s2...sn)</td>
<td>同 CONCAT(s1,s2,...) 函数，但是每个字符串之间要加上 x，x 可以是分隔符</td>
<td>
<p>合并多个字符串，并添加分隔符：</p>
<pre>
SELECT CONCAT_WS("-", "SQL", "Tutorial", "is", "fun!")AS ConcatenatedString;
</pre>
</td>
</tr>
<tr>
<td>FIELD(s,s1,s2...)</td>
<td>返回第一个字符串 s 在字符串列表(s1,s2...)中的位置</td>
<td>
<p>返回字符串 c 在列表值中的位置：</p>
<pre>
SELECT FIELD("c", "a", "b", "c", "d", "e");
</pre>
</td>
</tr>
<tr>
<td>FIND_IN_SET(s1,s2)</td>
<td>返回在字符串s2中与s1匹配的字符串的位置</td>
<td>
<p>返回字符串 c 在指定字符串中的位置：</p>
<pre>
SELECT FIND_IN_SET("c", "a,b,c,d,e");
</pre>
</td>
</tr>
<tr>
<td>FORMAT(x,n)</td>
<td>函数可以将数字 x 进行格式化 "#,###.##", 将 x 保留到小数点后 n 位，最后一位四舍五入。
</td>
<td>
<p>格式化数字 "#,###.##" 形式：</p>
<pre>
SELECT FORMAT(250500.5634, 2);     -- 输出 250,500.56
</pre>
</td>
</tr>
<tr>
<td>INSERT(s1,x,len,s2)</td>
<td>字符串 s2 替换 s1 的 x 位置开始长度为 len 的字符串</td>
<td>
<p>从字符串第一个位置开始的 6 个字符替换为 runoob：</p>
<pre>
SELECT INSERT("google.com", 1, 6, "runoob");  -- 输出：runoob.com
</pre>
</td>
</tr>
<tr>
<td>LOCATE(s1,s)</td>
<td>从字符串 s 中获取 s1 的开始位置</td>
<td>
<p>获取 b 在字符串 abc 中的位置：</p>
<pre>
SELECT LOCATE('st','myteststring');  -- 5
</pre>
<p>返回字符串 abc 中 b 的位置：</p>

<pre>SELECT LOCATE('b', 'abc') -- 2</pre>
</td>
</tr>
<tr>
<td>LCASE(s)</td>
<td>将字符串 s 的所有字母变成小写字母</td>
<td>
<p>字符串 RUNOOB 转换为小写：</p>
<pre>
SELECT LCASE('RUNOOB') -- runoob
</pre>
</td>
</tr>
<tr>
<td>LEFT(s,n)</td>
<td>返回字符串 s 的前 n 个字符</td>
<td>
<p>返回字符串 runoob 中的前两个字符：</p>
<pre>
SELECT LEFT('runoob',2) -- ru
</pre>

</td>
</tr>


<tr>
<td>LOWER(s)</td>
<td>将字符串 s 的所有字母变成小写字母</td>
<td>
<p>字符串 RUNOOB 转换为小写：</p>
<pre>
SELECT LOWER('RUNOOB') -- runoob
</pre>
</td>
</tr>
<tr>
<td>LPAD(s1,len,s2)</td>
<td>在字符串 s1 的开始处填充字符串 s2，使字符串长度达到 len</td>
<td>
<p>将字符串 xx 填充到 abc 字符串的开始处：</p>
<pre>
SELECT LPAD('abc',5,'xx') -- xxabc
</pre>
</td>
</tr>
<tr>
<td>LTRIM(s)</td>
<td>去掉字符串 s 开始处的空格</td>
<td>
<p>去掉字符串 RUNOOB开始处的空格：</p>
<pre>
SELECT LTRIM("    RUNOOB") AS LeftTrimmedString;-- RUNOOB
</pre>
</td>
</tr>
<tr>
<td>MID(s,n,len)</td>
<td>从字符串 s 的 n 位置截取长度为 len 的子字符串，同 SUBSTRING(s,n,len)</td>
<td>
<p>从字符串 RUNOOB 中的第 2 个位置截取 3个 字符：</p>
<pre>
SELECT MID("RUNOOB", 2, 3) AS ExtractString; -- UNO
</pre>
</td>
</tr>
<tr>
<td>POSITION(s1 IN s)</td>
<td>从字符串 s 中获取 s1 的开始位置</td>
<td>
<p>返回字符串 abc 中 b 的位置：</p>
<pre>
SELECT POSITION('b' in 'abc') -- 2
</pre>
</td>
</tr>
<tr>
<td>REPEAT(s,n)</td>
<td>将字符串 s 重复 n 次 </td>
<td>
<p>将字符串 runoob 重复三次：</p>
<pre>
SELECT REPEAT('runoob',3) -- runoobrunoobrunoob
</pre>
</td>
</tr>
<tr>
<td>REPLACE(s,s1,s2)</td>
<td>将字符串 s2 替代字符串 s 中的字符串 s1</td>
<td>
<p>将字符串 abc 中的字符 a 替换为字符 x：</p>
<pre>
SELECT REPLACE('abc','a','x') --xbc
</pre>
</td>
</tr>
<tr>
<td>REVERSE(s)</td>
<td>将字符串s的顺序反过来</td>
<td>
<p>将字符串 abc 的顺序反过来：</p>
<pre>
SELECT REVERSE('abc') -- cba
</pre>
</td>
</tr>
<tr>
<td>RIGHT(s,n)</td>
<td>返回字符串 s 的后 n 个字符</td>
<td>
<p>返回字符串 runoob 的后两个字符：</p>
<pre>
SELECT RIGHT('runoob',2) -- ob
</pre>
</td>
</tr>
<tr>
<td>RPAD(s1,len,s2)</td>
<td>在字符串 s1 的结尾处添加字符串 s2，使字符串的长度达到 len</td>
<td>
<p>将字符串 xx 填充到 abc 字符串的结尾处：</p>
<pre>
SELECT RPAD('abc',5,'xx') -- abcxx
</pre>
</td>
</tr>
<tr>
<td>RTRIM(s)</td>
<td>去掉字符串 s 结尾处的空格</td>
<td>
<p>去掉字符串 RUNOOB 的末尾空格：</p>
<pre>
SELECT RTRIM("RUNOOB     ") AS RightTrimmedString;   -- RUNOOB
</pre>
</td>
</tr>
<tr>
<td>SPACE(n)</td>
<td>返回 n 个空格</td>
<td>
<p>返回 10 个空格：</p>
<pre>
SELECT SPACE(10);
</pre>
</td>
</tr>
<tr>
<td>STRCMP(s1,s2)</td>
<td>比较字符串 s1 和 s2，如果 s1 与 s2 相等返回 0 ，如果 s1&gt;s2 返回 1，如果 s1&lt;s2 返回 -1</td>
<td>
<p>比较字符串：</p>
<pre>
SELECT STRCMP("runoob", "runoob");  -- 0
</pre>
</td>
</tr>
<tr>
<td>SUBSTR(s, start, length)</td>
<td>从字符串 s 的 start 位置截取长度为 length 的子字符串</td>
<td>
<p>从字符串 RUNOOB 中的第 2 个位置截取 3个 字符：</p>
<pre>
SELECT SUBSTR("RUNOOB", 2, 3) AS ExtractString; -- UNO
</pre>
</td>
</tr>
<tr>
<td>SUBSTRING(s, start, length)</td>
<td>从字符串 s 的 start 位置截取长度为 length 的子字符串，等同于 SUBSTR(s, start, length)</td>
<td>
<p>从字符串 RUNOOB 中的第 2 个位置截取 3个 字符：</p>
<pre>
SELECT SUBSTRING("RUNOOB", 2, 3) AS ExtractString; -- UNO
</pre>
</td>
</tr>
<tr>
<td>SUBSTRING_INDEX(s, delimiter, number)</td>
<td>返回从字符串 s 的第 number 个出现的分隔符 delimiter 之后的子串。<br>
如果 number 是正数，返回第 number 个字符左边的字符串。<br>

如果 number 是负数，返回第(number 的绝对值(从右边数))个字符右边的字符串。

</td>
<td>
<pre>
SELECT SUBSTRING_INDEX('a*b','*',1) -- a
SELECT SUBSTRING_INDEX('a*b','*',-1)&nbsp;&nbsp;&nbsp;&nbsp;-- b
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('a*b*c*d*e','*',3),'*',-1)&nbsp;&nbsp;&nbsp;&nbsp;-- c
</pre>
</td>
</tr>
<tr>
<td>TRIM(s)</td>
<td>去掉字符串 s 开始和结尾处的空格</td>
<td>
<p>去掉字符串 RUNOOB 的首尾空格：</p>
<pre>
SELECT TRIM('    RUNOOB    ') AS TrimmedString;
</pre>
</td>
</tr>
<tr>
<td>UCASE(s)</td>
<td>将字符串转换为大写</td>
<td>
<p>将字符串 runoob 转换为大写：</p>
<pre>
SELECT UCASE("runoob"); -- RUNOOB
</pre>
</td>
</tr>
<tr>
<td>UPPER(s)</td>
<td>将字符串转换为大写</td>
<td>
<p>将字符串 runoob 转换为大写：</p>
<pre>
SELECT UPPER("runoob"); -- RUNOOB
</pre>
</td>
</tr>
</tbody></table>

<hr><h2>
MySQL 数字函数</h2>

<table class="reference">
<tbody><tr>
<th style="width:25%">函数名</th>
<th>描述</th>
<th>实例</th>
</tr>
<tr>
<td>ABS(x)</td>
<td>返回 x 的绝对值　　</td>
<td>
<p>返回 -1 的绝对值：</p>
<pre>
SELECT ABS(-1) -- 返回1
</pre>
</td>
</tr>
<tr>
<td>ACOS(x)</td>
<td>求 x 的反余弦值（单位为弧度），x 为一个数值</td>
<td>
<pre>
SELECT ACOS(0.25);
</pre>
</td>
</tr>
<tr>
<td>ASIN(x)</td>
<td>求反正弦值（单位为弧度），x 为一个数值</td>
<td>
<pre>
SELECT ASIN(0.25);
</pre>
</td>
</tr>
<tr>
<td>ATAN(x)</td>
<td>求反正切值（单位为弧度），x 为一个数值</td>
<td>
<pre>
SELECT ATAN(2.5);
</pre>
</td>
</tr>
<tr>
<td>ATAN2(n, m)</td>
<td>求反正切值（单位为弧度）</td>
<td>
<pre>
SELECT ATAN2(-0.8, 2);
</pre>
</td>
</tr>
<tr>
<td>AVG(expression)</td>
<td>返回一个表达式的平均值，expression 是一个字段</td>
<td>
<p>返回 Products 表中Price 字段的平均值：</p>
<pre>
SELECT AVG(Price) AS AveragePrice FROM Products;
</pre>
</td>
</tr>
<tr>
<td>CEIL(x)</td>
<td>返回大于或等于 x 的最小整数　</td>
<td>
<pre>
SELECT CEIL(1.5) -- 返回2
</pre>
</td>
</tr>
<tr>
<td>CEILING(x)	
</td>
<td>返回大于或等于 x 的最小整数　</td>
<td>
<pre>
SELECT CEILING(1.5); -- 返回2
</pre>
</td>
</tr>
<tr>
<td>COS(x)</td>
<td>求余弦值(参数是弧度)</td>
<td>
<pre>
SELECT COS(2);
</pre>
</td>
</tr>
<tr>
<td>COT(x)</td>
<td>求余切值(参数是弧度)</td>
<td>
<pre>
SELECT COT(6);
</pre>
</td>
</tr>
<tr>
<td>COUNT(expression)</td>
<td>返回查询的记录总数，expression 参数是一个字段或者 * 号</td>
<td>
<p>返回 Products 表中 products 字段总共有多少条记录：</p>
<pre>
SELECT COUNT(ProductID) AS NumberOfProducts FROM Products;
</pre>
</td>
</tr>
<tr>
<td>DEGREES(x)</td>
<td>将弧度转换为角度　　</td>
<td>
<pre>
SELECT DEGREES(3.1415926535898) -- 180
</pre>
</td>
</tr>
<tr>
<td>n DIV m</td>
<td>整除，n 为被除数，m 为除数</td>
<td>
<p>计算 10 除于 5：</p>
<pre>
SELECT 10 DIV 5;  -- 2
</pre>
</td>
</tr>
<tr>
<td>EXP(x)</td>
<td>返回 e 的 x 次方　　</td>
<td>
<p>计算 e 的三次方：</p>
<pre>
SELECT EXP(3) -- 20.085536923188
</pre>
</td>
</tr>
<tr>
<td>FLOOR(x)</td>
<td>返回小于或等于 x 的最大整数　　</td>
<td>
<p>小于或等于 1.5 的整数：</p>
<pre>
SELECT FLOOR(1.5) -- 返回1
</pre>
</td>
</tr>
<tr>
<td>GREATEST(expr1, expr2, expr3, ...)</td>
<td>返回列表中的最大值</td>
<td>
<p>返回以下数字列表中的最大值：</p>
<pre>
SELECT GREATEST(3, 12, 34, 8, 25); -- 34
</pre>
<p>返回以下字符串列表中的最大值：</p><pre>
SELECT GREATEST("Google", "Runoob", "Apple");   -- Runoob
</pre>

</td>
</tr>
<tr>
<td>LEAST(expr1, expr2, expr3, ...)</td>
<td>返回列表中的最小值</td>
<td>
<p>返回以下数字列表中的最小值：</p>
<pre>
SELECT LEAST(3, 12, 34, 8, 25); -- 3
</pre>
<p>返回以下字符串列表中的最小值：</p><pre>
SELECT LEAST("Google", "Runoob", "Apple");   -- Apple
</pre>

</td>
</tr>
<tr>
<td>LN</td>
<td>返回数字的自然对数，以 e 为底。</td>
<td>
<p>返回 2 的自然对数：</p>
<pre>
SELECT LN(2);  -- 0.6931471805599453
</pre>

</td>
</tr>
<tr>
<td>LOG(x) 或 LOG(base, x)</td>
<td>返回自然对数(以 e 为底的对数)，如果带有 base 参数，则 base 为指定带底数。　　</td>
<td>
<pre>
SELECT LOG(20.085536923188) -- 3
SELECT LOG(2, 4); -- 2
</pre>

</td>
</tr>
<tr>
<td>LOG10(x)</td>
<td>返回以 10 为底的对数　　</td>
<td>
<pre>
SELECT LOG10(100) -- 2</pre>

</td>
</tr>
<tr>
<td>LOG2(x)</td>
<td>返回以 2 为底的对数</td>
<td>
<p>返回以 2 为底 6 的对数：</p>
<pre>
SELECT LOG2(6);  -- 2.584962500721156
</pre>

</td>
</tr>
<tr>
<td>MAX(expression)</td>
<td>返回字段 expression 中的最大值</td>
<td>
<p>返回数据表 Products 中字段 Price 的最大值：</p>
<pre>
SELECT MAX(Price) AS LargestPrice FROM Products;
</pre>

</td>
</tr>
<tr>
<td>MIN(expression)</td>
<td>返回字段 expression 中的最小值</td>
<td>
<p>返回数据表 Products 中字段 Price 的最小值：</p>
<pre>
SELECT MIN(Price) AS MinPrice FROM Products;
</pre>

</tr>
<tr>
<td>MOD(x,y)</td>
<td>返回 x 除以 y 以后的余数　</td>
<td>
<p>5 除于 2 的余数：</p>
<pre>
SELECT MOD(5,2) -- 1
</pre>

</td>
</tr>
<tr>
<td>PI()</td>
<td>返回圆周率(3.141593）　　</td>
<td>
<pre>
SELECT PI() --3.141593
</pre>

</td>
</tr>
<tr>
<td>POW(x,y)</td>
<td>返回 x 的 y 次方　</td>
<td>
<p>2 的 3 次方：</p>
<pre>
SELECT POW(2,3) -- 8
</pre>

</td>
</tr>
<tr>
<td>POWER(x,y)</td>
<td>返回 x 的 y 次方　</td>
<td>
<p>2 的 3 次方：</p>
<pre>
SELECT POWER(2,3) -- 8
</pre>
</tr>
<tr>
<td>RADIANS(x)</td>
<td>将角度转换为弧度　　</td>
<td>
<p>180 度转换为弧度：</p>
<pre>
SELECT RADIANS(180) -- 3.1415926535898
</pre>

</td>
</tr>
<tr>
<td>RAND()</td>
<td>返回 0 到 1 的随机数　　</td>
<td>
<pre>
SELECT RAND() --0.93099315644334
</pre>

</td>
</tr>
<tr>
<td>ROUND(x [,y])</td>
<td>返回离 x 最近的整数，可选参数 y 表示要四舍五入的小数位数，如果省略，则返回整数。</td>
<td>
<pre>
SELECT ROUND(1.23456) --1

SELECT ROUND(345.156, 2) -- 345.16
</pre>

</td>
</tr>
<tr>
<td>SIGN(x)</td>
<td>返回 x 的符号，x 是负数、0、正数分别返回 -1、0 和 1　</td>
<td>
<pre>
SELECT SIGN(-10) -- (-1)
</pre>

</td>
</tr>
<tr>
<td>SIN(x)</td>
<td>求正弦值(参数是弧度)　　</td>
<td>
<pre>
SELECT SIN(RADIANS(30)) -- 0.5
</pre>

</td>
</tr>
<tr>
<td>SQRT(x)</td>
<td>返回x的平方根　　</td>

<td>
<p>25 的平方根：</p>
<pre>
SELECT SQRT(25) -- 5
</pre>

</td>
</tr>
<tr>
<td>SUM(expression)</td>
<td>返回指定字段的总和</td>
<td>
<p>计算 OrderDetails 表中字段 Quantity 的总和：</p>
<pre>
SELECT SUM(Quantity) AS TotalItemsOrdered FROM OrderDetails;
</pre>

</td>
</tr>
<tr>
<td>TAN(x)</td>
<td>求正切值(参数是弧度)</td>
<td>
<pre>
SELECT TAN(1.75);  -- -5.52037992250933
</pre>

</td>
</tr>
<tr>
<td>TRUNCATE(x,y)</td>
<td>返回数值 x 保留到小数点后 y 位的值（与 ROUND 最大的区别是不会进行四舍五入）</td>
<td>
<pre>
SELECT TRUNCATE(1.23456,3) -- 1.234
</pre>

</td>
</tr>
</tbody></table>

<hr>
<h2>MySQL 日期函数</h2>
<table class="reference">
<tbody><tr>
<th style="width:25%">函数名</th>
<th>描述</th>
<th>实例</th>
</tr>
<tr>
<td>ADDDATE(d,n)</td>
<td>计算起始日期 d 加上 n 天的日期</td>
<td>
<pre>
SELECT ADDDATE("2017-06-15", INTERVAL 10 DAY);
-&gt;2017-06-25
</pre>

</td>
</tr>
<tr>
<td>ADDTIME(t,n)</td>
<td>n 是一个时间表达式，时间 t 加上时间表达式 n</td>
<td>
<p>加 5 秒：</p>
<pre>
SELECT ADDTIME('2011-11-11 11:11:11', 5);
-&gt;2011-11-11 11:11:16 (秒)
</pre>
<p>添加 2 小时, 10 分钟, 5 秒:</p>

<pre>
SELECT ADDTIME("2020-06-15 09:34:21", "2:10:5"); 
-&gt; 2020-06-15 11:44:26
</pre>
</td>
</tr>
<tr>
<td>CURDATE()</td>
<td>返回当前日期</td>
<td>
<pre>
SELECT CURDATE();
-&gt; 2018-09-19
</pre>

</td>
</tr>
<tr>
<td>CURRENT_DATE()</td>
<td>返回当前日期</td>
<td>
<pre>
SELECT CURRENT_DATE();
-&gt; 2018-09-19
</pre>

</td>
</tr>
<tr>
<td>CURRENT_TIME</td>
<td>返回当前时间</td>
<td>
<pre>
SELECT CURRENT_TIME();
-&gt; 19:59:02
</pre>

</td>
</tr>
<tr>
<td>CURRENT_TIMESTAMP()</td>
<td>返回当前日期和时间</td>
<td>
<pre>
SELECT CURRENT_TIMESTAMP()
-&gt; 2018-09-19 20:57:43
</pre>

</td>
</tr>
<tr>
<td>CURTIME()</td>
<td>返回当前时间</td>
<td>
<pre>
SELECT CURTIME();
-&gt; 19:59:02
</pre>
</tr>
<tr>
<td>DATE()</td>
<td>从日期或日期时间表达式中提取日期值</td>
<td>
<pre>
SELECT DATE("2017-06-15");    
-&gt; 2017-06-15
</pre>

</td>
</tr>
<tr>
<td>DATEDIFF(d1,d2)</td>
<td>计算日期 d1-&gt;d2 之间相隔的天数</td>
<td>
<pre>
SELECT DATEDIFF('2001-01-01','2001-02-02')
-&gt; -32
</pre>

</td>
</tr>
<tr>
<td>DATE_ADD(d，INTERVAL expr type)</td>
<td>计算起始日期 d 加上一个时间段后的日期，type 值可以是：
<ul>
      <li>MICROSECOND</li>
      <li>SECOND</li>
      <li>MINUTE</li>
      <li>HOUR</li>
      <li>DAY</li>
      <li>WEEK</li>
      <li>MONTH</li>
      <li>QUARTER</li>
      <li>YEAR</li>
      <li>SECOND_MICROSECOND</li>
      <li>MINUTE_MICROSECOND</li>
      <li>MINUTE_SECOND</li>
      <li>HOUR_MICROSECOND</li>
      <li>HOUR_SECOND</li>
      <li>HOUR_MINUTE</li>
      <li>DAY_MICROSECOND</li>
      <li>DAY_SECOND</li>
      <li>DAY_MINUTE</li>
      <li>DAY_HOUR</li>
      <li>YEAR_MONTH</li>
    </ul></td>
<td>
<pre>
SELECT DATE_ADD("2017-06-15", INTERVAL 10 DAY);    
-&gt; 2017-06-25

SELECT DATE_ADD("2017-06-15 09:34:21", INTERVAL 15 MINUTE);
-&gt; 2017-06-15 09:49:21

SELECT DATE_ADD("2017-06-15 09:34:21", INTERVAL -3 HOUR);
-&gt;2017-06-15 06:34:21

SELECT DATE_ADD("2017-06-15 09:34:21", INTERVAL -3 MONTH);
-&gt;2017-04-15
</pre>

</td>
</tr>
<tr>
<td>DATE_FORMAT(d,f)</td>
<td>按表达式  f的要求显示日期 d</td>
<td>
<pre>
SELECT DATE_FORMAT('2011-11-11 11:11:11','%Y-%m-%d %r')
-&gt; 2011-11-11 11:11:11 AM
</pre>

</td>
</tr>
<tr>
<td>DATE_SUB(date,INTERVAL expr type)</td>
<td>函数从日期减去指定的时间间隔。</td>
<td>
 <p>Orders 表中 OrderDate 字段减去 2 天：</p>
<pre>
SELECT OrderId,DATE_SUB(OrderDate,INTERVAL 2 DAY) AS OrderPayDate
FROM Orders
</pre>

</td>
</tr>
<tr>
<td>DAY(d)</td>
<td>返回日期值 d 的日期部分</td>
<td>
<pre>
SELECT DAY("2017-06-15");  
-&gt; 15
</pre>

</td>
</tr>
<tr>
<td>DAYNAME(d)</a></td>
<td>返回日期 d 是星期几，如 Monday,Tuesday</td>
<td>
<pre>
SELECT DAYNAME('2011-11-11 11:11:11')
-&gt;Friday
</pre>

</td>
</tr>
<tr>
<td>DAYOFMONTH(d)</td>
<td>计算日期 d 是本月的第几天</td>
<td>
<pre>
SELECT DAYOFMONTH('2011-11-11 11:11:11')
-&gt;11
</pre>

</td>
</tr>
<tr>
<td>DAYOFWEEK(d)</td>
<td>日期 d 今天是星期几，1 星期日，2 星期一，以此类推</td>
<td>
<pre>
SELECT DAYOFWEEK('2011-11-11 11:11:11')
-&gt;6
</pre>

</td>
</tr>
<tr>
<td>DAYOFYEAR(d)</td>
<td>计算日期 d 是本年的第几天</td>
<td>
<pre>
SELECT DAYOFYEAR('2011-11-11 11:11:11')
-&gt;315
</pre>

</td>
</tr>
<tr>
<td>EXTRACT(type FROM d)</td>
<td>从日期 d 中获取指定的值，type 指定返回的值。
<br>

type可取值为：
<br><ul><li>
MICROSECOND</li><li>
SECOND</li><li>
MINUTE</li><li>
HOUR</li><li>
DAY</li><li>
WEEK</li><li>
MONTH</li><li>
QUARTER</li><li>
YEAR</li><li>
SECOND_MICROSECOND</li><li>
MINUTE_MICROSECOND</li><li>
MINUTE_SECOND</li><li>
HOUR_MICROSECOND</li><li>
HOUR_SECOND</li><li>
HOUR_MINUTE</li><li>
DAY_MICROSECOND</li><li>
DAY_SECOND</li><li>
DAY_MINUTE</li><li>
DAY_HOUR</li><li>
YEAR_MONTH</li></ul></td>

<td>
<pre>
SELECT EXTRACT(MINUTE FROM '2011-11-11 11:11:11') 
-&gt; 11
</pre>

</td>

</tr>
<tr>
<td>FROM_DAYS(n)</a></td>
<td>计算从 0000 年 1 月 1 日开始 n 天后的日期</td>
<td>
<pre>
SELECT FROM_DAYS(1111)
-&gt; 0003-01-16
</pre>

</td>
</tr>
<tr>
<td>HOUR(t)</td>
<td>返回 t 中的小时值</td>
<td>
<pre>
SELECT HOUR('1:2:3')
-&gt; 1
</pre>

</td>
</tr>
<tr>
<td>LAST_DAY(d)</td>
<td>返回给给定日期的那一月份的最后一天</td>
<td>
<pre>
SELECT LAST_DAY("2017-06-20");
-&gt; 2017-06-30
</pre>

</td>
</tr>
<tr>
<td>LOCALTIME()</td>
<td>返回当前日期和时间</td>
<td>
<pre>
SELECT LOCALTIME()
-&gt; 2018-09-19 20:57:43
</pre>
</td>
</tr>
<tr>
<td>LOCALTIMESTAMP()</td>
<td>返回当前日期和时间</td>
<td>
<pre>
SELECT LOCALTIMESTAMP()
-&gt; 2018-09-19 20:57:43
</pre>
</td>
</tr>
<tr>
<td>MAKEDATE(year, day-of-year)</td>
<td>基于给定参数年份 year 和所在年中的天数序号 day-of-year 返回一个日期</td>
<td>
<pre>
SELECT MAKEDATE(2017, 3);
-&gt; 2017-01-03
</pre>

</td>
</tr>
<tr>
<td>MAKETIME(hour, minute, second)</td>
<td>组合时间，参数分别为小时、分钟、秒</td>
<td>
<pre>
SELECT MAKETIME(11, 35, 4);
-&gt; 11:35:04
</pre>

</td>
</tr>
<tr>
<td>MICROSECOND(date)</td>
<td>返回日期参数所对应的微秒数</td>
<td>
<pre>
SELECT MICROSECOND("2017-06-20 09:34:00.000023");
-&gt; 23
</pre>

</td>
</tr>
<tr>
<td>MINUTE(t)</td>
<td>返回 t 中的分钟值</td>
<td>
<pre>
SELECT MINUTE('1:2:3')
-&gt; 2
</pre>

</td>
</tr>
<tr>
<td>MONTHNAME(d)</td>
<td>返回日期当中的月份名称，如 November</td>
<td>
<pre>
SELECT MONTHNAME('2011-11-11 11:11:11')
-&gt; November
</pre>

</td>
</tr>
<tr>
<td>MONTH(d)</td>
<td>返回日期d中的月份值，1 到 12</td>
<td>
<pre>
SELECT MONTH('2011-11-11 11:11:11')
-&gt;11
</pre>

</td>
</tr>
<tr>
<td>NOW()</td>
<td>返回当前日期和时间</td>
<td>
<pre>
SELECT NOW()
-&gt; 2018-09-19 20:57:43
</pre>

</td>
</tr>
<tr>
<td>PERIOD_ADD(period, number)</td>
<td>为 年-月 组合日期添加一个时段</td>
<td>
<pre>
SELECT PERIOD_ADD(201703, 5);   
-&gt; 201708
</pre>

</td>
</tr>
<tr>
<td>PERIOD_DIFF(period1, period2)</td>
<td>返回两个时段之间的月份差值</td>
<td>
<pre>
SELECT PERIOD_DIFF(201710, 201703);
-&gt; 7
</pre>

</td>
</tr>
<tr>
<td>QUARTER(d)</td>
<td>返回日期d是第几季节，返回 1 到 4</td>
<td>
<pre>
SELECT QUARTER('2011-11-11 11:11:11')
-&gt; 4
</pre>

</td>
</tr>
<tr>
<td>SECOND(t)</td>
<td>返回 t 中的秒钟值</td>
<td>
<pre>
SELECT SECOND('1:2:3')
-&gt; 3
</pre>

</td>
</tr>
<tr>
<td>SEC_TO_TIME(s)</td>
<td>将以秒为单位的时间 s 转换为时分秒的格式</td>
<td>
<pre>
SELECT SEC_TO_TIME(4320)
-&gt; 01:12:00
</pre>

</td>
</tr>
<tr>
<td>STR_TO_DATE(string, format_mask)</td>
<td>将字符串转变为日期</td>
<td>
<pre>
SELECT STR_TO_DATE("August 10 2017", "%M %d %Y");
-&gt; 2017-08-10
</pre>

</td>
</tr>
<tr>
<td>SUBDATE(d,n)</td>
<td>日期 d 减去 n 天后的日期</td>
<td>
<pre>
SELECT SUBDATE('2011-11-11 11:11:11', 1)
-&gt;2011-11-10 11:11:11 (默认是天)
</pre>

</td>
</tr>
<tr>
<td>SUBTIME(t,n)</td>
<td>时间 t 减去 n 秒的时间</td>
<td>
<pre>
SELECT SUBTIME('2011-11-11 11:11:11', 5)
-&gt;2011-11-11 11:11:06 (秒)
</pre>

</td>
</tr>
<tr>
<td>SYSDATE()</td>
<td>返回当前日期和时间</td>
<td>
<pre>
SELECT SYSDATE()
-&gt; 2018-09-19 20:57:43
</pre>

</td>
</tr>
<tr>
<td>TIME(expression)</td>
<td>提取传入表达式的时间部分</td>
<td>
<pre>
SELECT TIME("19:30:10");
-&gt; 19:30:10
</pre>

</td>
</tr>
<tr>
<td>TIME_FORMAT(t,f)</td>
<td>按表达式 f 的要求显示时间 t</td>
<td>
<pre>
SELECT TIME_FORMAT('11:11:11','%r')
11:11:11 AM
</pre>

</td>
</tr>
<tr>
<td>TIME_TO_SEC(t)</td>
<td>将时间 t 转换为秒</td>
<td>
<pre>
SELECT TIME_TO_SEC('1:12:00')
-&gt; 4320
</pre>

</td>
</tr>
  <tr>
<td>TIMEDIFF(time1, time2)</td>
<td>计算时间差值</td>
<td>
<pre>
mysql&gt; SELECT TIMEDIFF("13:10:11", "13:10:10");
-&gt; 00:00:01
mysql&gt; SELECT TIMEDIFF('2000:01:01 00:00:00',
    -&gt;                 '2000:01:01 00:00:00.000001');
        -&gt; '-00:00:00.000001'
mysql&gt; SELECT TIMEDIFF('2008-12-31 23:59:59.000001',
    -&gt;                 '2008-12-30 01:01:01.000002');
        -&gt; '46:58:57.999999'
</pre>

</td>
  </tr>
  <tr>
<td>TIMESTAMP(expression, interval)</td>
<td>单个参数时，函数返回日期或日期时间表达式；有2个参数时，将参数加和</td>
<td>
<pre>
mysql&gt; SELECT TIMESTAMP("2017-07-23",  "13:10:11");
-&gt; 2017-07-23 13:10:11
mysql&gt; SELECT TIMESTAMP('2003-12-31');
        -&gt; '2003-12-31 00:00:00'
mysql&gt; SELECT TIMESTAMP('2003-12-31 12:00:00','12:00:00');
        -&gt; '2004-01-01 00:00:00'
</pre>

</td>
  </tr>

  <tr>
<td>TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2)</td>
<td>计算时间差，返回 datetime_expr2 − datetime_expr1 的时间差</td>
<td>
<pre>
mysql&gt; SELECT TIMESTAMPDIFF(DAY,'2003-02-01','2003-05-01');   // 计算两个时间相隔多少天
        -&gt; 89
mysql&gt; SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01');   // 计算两个时间相隔多少月
        -&gt; 3
mysql&gt; SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01');    // 计算两个时间相隔多少年
        -&gt; -1
mysql&gt; SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55');  // 计算两个时间相隔多少分钟
        -&gt; 128885
</pre>

</td>
  </tr>



<tr>
<td>TO_DAYS(d)</td>
<td>计算日期 d 距离 0000 年 1 月 1 日的天数</td>
<td>
<pre>
SELECT TO_DAYS('0001-01-01 01:01:01')
-&gt; 366
</pre>

</td>
</tr>
<tr>
<td>WEEK(d)</td>
<td>计算日期 d 是本年的第几个星期，范围是 0 到 53</td>
<td>
<pre>
SELECT WEEK('2011-11-11 11:11:11')
-&gt; 45
</pre>

</td>
</tr>
<tr>
<td>WEEKDAY(d)</td>
<td>日期 d 是星期几，0 表示星期一，1 表示星期二</td>
<td>
<pre>
SELECT WEEKDAY("2017-06-15");
-&gt; 3
</pre>

</td>
</tr>
<tr>
<td>WEEKOFYEAR(d)</td>
<td>计算日期 d 是本年的第几个星期，范围是 0 到 53</td>
<td>
<pre>
SELECT WEEKOFYEAR('2011-11-11 11:11:11')
-&gt; 45
</pre>

</td>
</tr>
<tr>
<td>YEAR(d)</td>
<td>返回年份</td>
<td>
<pre>
SELECT YEAR("2017-06-15");
-&gt; 2017
</pre>

</td>
</tr>
<tr>
<td>YEARWEEK(date, mode)</td>
<td>返回年份及第几周（0到53），mode 中 0 表示周天，1表示周一，以此类推</td>
<td>
<pre>
SELECT YEARWEEK("2017-06-15");
-&gt; 201724
</pre>

</td>
</tr>
</tbody></table>
<hr>
<h2>MySQL 高级函数</h2>
<table class="reference">
<tbody><tr>
<th style="width:25%">函数名</th>
<th>描述</th>
<th>实例</th>
</tr>
<tr>
<td>BIN(x)</td>
<td> 返回 x 的二进制编码</td>
<td>
<p> 15 的 2 进制编码:</p>
<pre>
SELECT BIN(15); -- 1111
</pre>

</td>
</tr>
<tr>
<td>BINARY(s)</td>
<td>将字符串 s 转换为二进制字符串</td>
<td>
<pre>
SELECT BINARY "RUNOOB";
-&gt; RUNOOB
</pre>

</td>
</tr>
<tr>
<td><pre>
CASE expression
    WHEN condition1 THEN result1
    WHEN condition2 THEN result2
   ...
    WHEN conditionN THEN resultN
    ELSE result
END</pre>
</td>
<td>CASE 表示函数开始，END 表示函数结束。如果 condition1 成立，则返回 result1, 如果 condition2 成立，则返回 result2，当全部不成立则返回 result，而当有一个成立之后，后面的就不执行了。</td>
<td>
<pre>
SELECT CASE 
　　WHEN 1 &gt; 0
　　THEN '1 &gt; 0'
　　WHEN 2 &gt; 0
　　THEN '2 &gt; 0'
　　ELSE '3 &gt; 0'
　　END
-&gt;1 &gt; 0
</pre>

</td>
</tr>
<tr>
<td>CAST(x AS type)</td>
<td>转换数据类型</td>
<td>
<p>字符串日期转换为日期：</p>
<pre>
SELECT CAST("2017-08-29" AS DATE);
-&gt; 2017-08-29
</pre>

</td>
</tr>
<tr>
<td>COALESCE(expr1, expr2, ...., expr_n)</td>
<td>返回参数中的第一个非空表达式（从左向右）</td>
<td>
<pre>
SELECT COALESCE(NULL, NULL, NULL, 'runoob.com', NULL, 'google.com');
-&gt; runoob.com
</pre>

</td>
</tr>
<tr>
<td>CONNECTION_ID()</td>
<td>返回唯一的连接 ID</td>
<td>
<pre>
SELECT CONNECTION_ID();
-&gt; 4292835
</pre>

</td>
</tr>
<tr>
<td>CONV(x,f1,f2)</td>
<td>返回 f1 进制数变成 f2 进制数</td>
<td>
<pre>
SELECT CONV(15, 10, 2);
-&gt; 1111
</pre>

</td>
</tr>
<tr>
<td>CONVERT(s USING cs)</td>
<td>函数将字符串 s 的字符集变成 cs</td>
<td>
<pre>
SELECT CHARSET('ABC')
-&gt;utf-8    

SELECT CHARSET(CONVERT('ABC' USING gbk))
-&gt;gbk
</pre>

</td>
</tr>
<tr>
<td>CURRENT_USER()</td>
<td>返回当前用户</td>
<td>
<pre>
SELECT CURRENT_USER();
-&gt; guest@%
</pre>

</td>
</tr>
<tr>
<td>DATABASE()</td>
<td>返回当前数据库名</td>
<td>
<pre>
SELECT DATABASE();   
-&gt; runoob
</pre>

</td>
</tr>
<tr>
<td>IF(expr,v1,v2)</td>
<td>如果表达式 expr 成立，返回结果 v1；否则，返回结果 v2。</td>
<td>
<pre>
SELECT IF(1 &gt; 0,'正确','错误')    
-&gt;正确
</pre>

</td>
</tr>
<tr>
<td><a href="../mysql/mysql-func-ifnull.html" rel="noopener noreferrer" target="_blank">IFNULL(v1,v2)</a></td>
<td>如果 v1 的值不为 NULL，则返回 v1，否则返回 v2。</td>
<td>
<pre>
SELECT IFNULL(null,'Hello Word')
-&gt;Hello Word
</pre>

</td>
</tr>
<tr>
<td>ISNULL(expression)</td>
<td>判断表达式是否为 NULL</td>
<td>
<pre>
SELECT ISNULL(NULL);
-&gt;1
</pre>

</td>
</tr>
<tr>
<td>LAST_INSERT_ID()</td>
<td>返回最近生成的 AUTO_INCREMENT 值</td>
<td>
<pre>
SELECT LAST_INSERT_ID();
-&gt;6
</pre>

</td>
</tr>
<tr>
<td>NULLIF(expr1, expr2)</td>
<td>比较两个字符串，如果字符串 expr1 与 expr2 相等 返回 NULL，否则返回 expr1 </td>
<td>
<pre>
SELECT NULLIF(25, 25);
-&gt;
</pre>

</td>
</tr>
<tr>
<td>SESSION_USER()</td>
<td>返回当前用户</td>
<td>
<pre>
SELECT SESSION_USER();
-&gt; guest@%
</pre>
</tr>
<tr>
<td>SYSTEM_USER()</td>
<td>返回当前用户</td>
<td>
<pre>
SELECT SYSTEM_USER();
-&gt; guest@%
</pre>
</tr>
<tr>
<td>USER()</td>
<td>返回当前用户</td>
<td>
<pre>
SELECT USER();
-&gt; guest@%
</pre>
</tr>
<tr>
<td>VERSION()</td>
<td>返回数据库的版本号</td>
<td>
<pre>
SELECT VERSION()
-&gt; 5.6.34
</pre>

</td>
</tr>
</tbody></table>

<p>以下是 MySQL 8.0 版本新增的一些常用函数：</p>

<table class="reference"><thead><tr><th>函数</th><th>描述</th><th>实例</th></tr></thead><tbody>
<tr><td>JSON_OBJECT()</td><td>将键值对转换为 JSON 对象</td>
<td><pre>SELECT JSON_OBJECT('key1', 'value1', 'key2', 'value2')</pre></td></tr>
<tr><td>JSON_ARRAY()</td><td>将值转换为 JSON 数组</td><td><pre>SELECT JSON_ARRAY(1, 2, 'three')</pre></td></tr><tr><td>JSON_EXTRACT()</td><td>从 JSON 字符串中提取指定的值</td><td><pre>SELECT JSON_EXTRACT('{"name": "John", "age": 30}', '$.name')</pre></td></tr><tr><td>JSON_CONTAINS()</td><td>检查一个 JSON 字符串是否包含指定的值</td><td><pre>SELECT JSON_CONTAINS('{"name": "John", "age": 30}', 'John', '$.name')</pre></td></tr><tr><td>ROW_NUMBER()</td><td>为查询结果中的每一行分配一个唯一的数字</td><td><pre>SELECT ROW_NUMBER() OVER(ORDER BY id) AS row_number, name FROM users</pre></td></tr><tr><td>RANK()</td><td>为查询结果中的每一行分配一个排名</td><td><pre>SELECT RANK() OVER(ORDER BY score DESC) AS rank, name, score FROM students</pre></td></tr></tbody></table>			<!-- 其他扩展 -->
						
			</div>
			
		</div>
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../mysql/mysql-union-operation.html" rel="prev"> MySQL UNION 操作符</a> </div>
			<div class="next-design-link"><a href="../mysql/mysql-func-ifnull.html" rel="next"> MySQL IFNULL() 函数</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
		<!-- 笔记列表 -->
		<style>
.wrapper {
  /*text-transform: uppercase; */
  background: #ececec;
  color: #555;
  cursor: help;
  font-family: "Gill Sans", Impact, sans-serif;
  font-size: 20px;
  position: relative;
  text-align: center;
  width: 200px;
  -webkit-transform: translateZ(0); /* webkit flicker fix */
  -webkit-font-smoothing: antialiased; /* webkit text rendering fix */
}

.wrapper .tooltip {
  white-space: nowrap;
  font-size: 14px;
  text-align: left;
  background: #96b97d;
  bottom: 100%;
  color: #fff;
  display: block;
  left: -25px;
  margin-bottom: 15px;
  opacity: 0;
  padding: 14px;
  pointer-events: none;
  position: absolute;
  
  -webkit-transform: translateY(10px);
     -moz-transform: translateY(10px);
      -ms-transform: translateY(10px);
       -o-transform: translateY(10px);
          transform: translateY(10px);
  -webkit-transition: all .25s ease-out;
     -moz-transition: all .25s ease-out;
      -ms-transition: all .25s ease-out;
       -o-transition: all .25s ease-out;
          transition: all .25s ease-out;
  -webkit-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
     -moz-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
      -ms-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
       -o-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
          box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
}
.tooltip a {
	color:#fff;
}
/* This bridges the gap so you can mouse into the tooltip without it disappearing */
.wrapper .tooltip:before {
  bottom: -20px;
  content: " ";
  display: block;
  height: 20px;
  left: 0;
  position: absolute;
  width: 100%;
}  

/* CSS Triangles - see Trevor's post */
.wrapper .tooltip:after {
  border-left: solid transparent 10px;
  border-right: solid transparent 10px;
  border-top: solid #96b97d 10px;
  bottom: -10px;
  content: " ";
  height: 0;
  left: 20%;
  margin-left: -13px;
  position: absolute;
  width: 0;
}
.wrapper .tooltip1 {
	margin-left: 50px;
	padding-top: 0px;
}
/*
.wrapper:hover .tooltip {
  opacity: 1;
  pointer-events: auto;
  -webkit-transform: translateY(0px);
     -moz-transform: translateY(0px);
      -ms-transform: translateY(0px);
       -o-transform: translateY(0px);
          transform: translateY(0px);
}
*/
/* IE can just show/hide with no transition */
.lte8 .wrapper .tooltip {
  display: none;
}

.lte8 .wrapper:hover .tooltip {
  display: block;
}

</style>

<link rel="stylesheet" href="../0/upvotejs.css">
<script src=""></script>
<script src=""></script>
<div class="title" id="comments">
	<h2 class="">
    <div class="altblock">
		    	<i style="font-size:28px;margin-top: 8px;" class="fa fa-pencil-square-o" aria-hidden="true"></i>
    	    </div>
    <span class="mw-headline" id="qa_headline">1  篇笔记</span>
	<span class="mw-headline" id="user_add_note" style="float:right;line-height: 62px;padding-right: 14px;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>  写笔记</span>
    </h2>
</div>

<div id="postcomments"   >
	<ol class="commentlist">
		<li class="comment even thread-even depth-1" id="comment-40404"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;宋新峰</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;son***nfeng1024@126.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://blog.csdn.net/songxinfeng1989/article/details/81906713">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-40404" data-commid = "40404" class="upvotejs"><a class="upvote"></a> <span class="count">337</span></div></div><div class="comt-main" id="div-comment-40404"><p><strong>需求：</strong>将数据库中每分钟一条的数据表，从 9:30 取到 22:00 ，以半小时为单位汇总，并输出 Excel。</p>

<p>数据表字段：id（序号）、incount（计数）、cdate（数据时间）</p>

<p>表名：m_temp</p>

<p>难点：时间处理</p>

<p>解决办法：使用 DATE_FORMAT、CONCAT、Date、Hour、Minute、Floor 函数将时间处理成半小时，在将这段时间的数据查询时 输出 cdate 统一变为  09:30，然后在 group by cdate ，用 sum（incount）求和。</p>

<p>1.处理时间：</p>

<p>示例：2018-08-21 09:30:00   至 2018-08-21 22:00:00</p>
<p>第一个半小时 09:30 至 10:00</p>

<p>将这段时间的数据查询时 输出 cdate 统一变为 09:30，然后在 group by cdate ，sum（incount）</p>

<p>将分钟取出 /30  , 0-29 分结果为 0 ，30-59分结果为 1 再乘以 30 分钟即变为 00 或者 30</p>

<p>date(cdate)，取出年月日；</p>

<p>hour(cdate)，取出小时；</p>

<p>minute(cdate)，取出分钟；</p>

<p>计算（minute(cdate)）/30 )*30，结果为 0 或30；</p>

<p>floor( （minute(cdate)）/30 )*30)， 处理成整数；</p>

<p>concat(date(cdate),' ',hour(cdate),':',floor( （minute(cdate)）/30 )*30) ，按照日期格式进行拼接</p>

<p>DATE_FORMAT( concat(date(cdate),' ',hour(cdate),':',floor( minute(cdate)/30 )*30+12) ,'%Y-%m-%d %H:%i') ，转换成date类型</p>

<p>完整 SQL：</p>
<pre>select sum(incount),dataStartTime from (
select incount, DATE_FORMAT( concat(date(cdate),' ',hour(cdate),':',floor( minute(cdate)/30 )*30+12) ,'%Y-%m-%d %H:%i')  as dataStartTime   
 from m_temp WHERE cdate&gt;='2018-08-21 09:30' and cdate&lt;='2018-08-21 22:00'  ORDER BY dataStartTime
) a
group by DATE_FORMAT( dataStartTime ,'%Y-%m-%d %H:%i')
into outfile('c:/2018-08-21Data.xls');</pre>
<div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">宋新峰</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;宋新峰</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;son***nfeng1024@126.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://blog.csdn.net/songxinfeng1989/article/details/81906713">&nbsp;&nbsp;参考地址</a></p></div></span>4年前 (2019-03-05)</div></div></li><!-- #comment-## -->
	</ol>
	<div class="pagenav">
			</div>
</div>
<div id="respond" class="no_webshot"> 
		<div class="comment-signarea" style="display:none; padding: 20px 20px;"> 
	<h3 class="text-muted" id="share_code" style="color: #799961;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> 点我分享笔记</h3>
	<!--
	<p style="font-size:14px;">笔记需要是本篇文章的内容扩展！</p><br>
	<p style="font-size:12px;"><a href="../tougao" target="_blank">文章投稿，可点击这里</a></p>
	<p style="font-size:14px;"><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>
		<h3 class="text-muted"><i class="fa fa-info-circle" aria-hidden="true"></i> 分享笔记前必须<a href="javascript:;" class="runoob-pop">登录</a>！</h3>
		<p><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>-->
	</div>
		
	<form action="/wp-content/themes/runoob/option/addnote.php" method="post" id="commentform" style="display:none;">
		<div class="comt">
			<div class="comt-title">
				<i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i>				<p><a id="cancel-comment-reply-link" href="javascript:;">取消</a></p>
			</div>
			<div class="comt-box">
			<div id="mded"></div>
			
				<div class="comt-ctrl">
					<div class="comt-tips"><input type='hidden' name='comment_post_ID' value='20753' id='comment_post_ID' />
<input type='hidden' name='comment_parent' id='comment_parent' value='0' />
</div>
					<button type="submit" name="submit" id="submit" tabindex="5"><i class="fa fa-pencil" aria-hidden="true"></i> 分享笔记</button>
				</div>
			</div>
		
				
					<div class="comt-comterinfo"> 
						<ul id="comment-author-info">
							<li class="form-inline"><label class="hide" for="author">昵称</label><input class="ipt" type="text" name="author" id="author" value="" tabindex="2" placeholder="昵称"><span class="text-muted">昵称 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="email">邮箱</label><input class="ipt" type="text" name="email" id="email" value="" tabindex="3" placeholder="邮箱"><span class="text-muted">邮箱 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="url">引用地址</label><input class="ipt" type="text" name="url" id="url" value="" tabindex="4" placeholder="引用地址"><span class="text-muted">引用地址</span></li>
						</ul>
					</div>
				
			
		</div>

	</form>
	</div>
<script type="text/javascript">
$(function() {
	//初始化编辑器
	
	var editor = new Simditor({
	  textarea: $('#mded'),
	  placeholder: '写笔记...',
	  upload:false,
	 // upload: {url:'/api/comment_upload_file.php',params: null,fileKey: 'upload_file',connectionCount: 1,leaveConfirm: '文件正在上传，您确定离开?'},
	  defaultImage: 'https://www.runoob.com/images/logo.png',
	  codeLanguages: '',
	  autosave: 'editor-content',
	  toolbar: [  'bold','code','ul','ol','image' ]
	});
	editor.on('selectionchanged', function() {
		$(".code-popover").hide();
	});

	// 提交数据
	$("#share_code").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		
	});
	$("#user_add_note").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		$('html, body').animate({
       	    scrollTop: $("#respond").offset().top
    	}, 200);
	});

	// 提交笔记
	var commentform=$('#commentform');
	commentform.prepend('<div id="comment-status" style="display:none;" ></div>');
	var statusdiv=$('#comment-status');
	
	commentform.submit(function(e){
		e.preventDefault();
		var noteContent = editor.getValue();
		// console.log(noteContent);
		noteContent = noteContent.replace(/<pre><code>/g,"<pre>");
		noteContent = noteContent.replace(/<\/code><\/pre>/g,"</pre>");
		
		// 系列化表单数据
		var comment_parent = 0;
		var is_user_logged_in = $("#is_user_logged_in").val();
		var comment_post_ID =  20753;
		var _wp_unfiltered_html_comment = $("#_wp_unfiltered_html_comment").val();
		var comment = noteContent;
		var author = $("#author").val();
		var url = $("#url").val();
		var email = $("#email").val();
		if(isBlank(author) && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入昵称！</p>').show();
		} else if(isBlank(email)  && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入邮箱！</p>').show();
		} else {
			// var formdata=commentform.serialize() + "&comment=" + noteContent ;
			// 添加状态信息
			statusdiv.html('<p>Processing...</p>').show();
			// 获取表单提交地址
			var formurl=commentform.attr('action');
			
			// 异步提交
			$.ajax({
					type: 'post',
					url: formurl,
					dataType:'json',
					data: {"comment_parent":comment_parent,"comment_post_ID":comment_post_ID, "_wp_unfiltered_html_comment":_wp_unfiltered_html_comment,"comment":comment,"url":url, "email":email,"author":author},
					error: function(XMLHttpRequest, textStatus, errorThrown){
					statusdiv.html('<p class="ajax-error" >数据不完整或表单提交太快了！</p>').show();
				},
				success: function(data, textStatus){
					if(data.errorno=="0") {
						$("#submit").prop('disabled', true);
						statusdiv.html('<p class="ajax-success" >笔记已提交审核，感谢分享笔记！</p>').show();
						alert('笔记已提交审核，感谢分享笔记！');
					}else{
						statusdiv.html('<p class="ajax-error" >'+data.msg+'</p>').show();
					}
					commentform.find('textarea[name=comment]').val('');
				}
			});
			setTimeout(function(){
		        $("#submit").prop('disabled', false);
		    }, 10*1000);
		}
		return false;

	});
	$(".comt-author").click(function() {
		href = $(this).children("a").attr("href");
		if(href.indexOf("/note/")!=-1) {
			var win = window.open(href, '_blank');
  			win.focus();
		}
	});
	$(".comt-meta span").hover(function(){
		$(this).children(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).children(".tooltip").removeAttr("style");
	});
	/*
	$(".wrapper i").hover(function(){
		$(this).siblings(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).siblings(".tooltip").css({ "opacity": 0, "pointer-events": "auto"});
	});
	*/
	//Upvote.create('runoobvote-id', {callback: vote_callback});
	var ajaxurl = 'https://www.runoob.com/wp-admin/admin-ajax.php';
	var callback = function(data) {
		//console.log($('#runoobvote-id').upvote('upvoted'));
		//console.log($('#runoobvote-id').upvote('downvoted'));
		//console.log(data);
		_vote_action = data.action;
		id_arr = data.id.split('-');
		um_id= id_arr[2];
		//console.log(um_id);
		
		var re = /^[1-9]+/;
		if (re.test(um_id)) { 
			var ajax_data = {
				_vote_action: _vote_action,
				action: "pinglun_zan",
				um_id: um_id,
				um_action: "ding"
			};
			//console.log(ajax_data);
			$.post(ajaxurl,ajax_data,function(status){
				//if(status.vote_num>999) {
				//	_voteHtml = '<span style="display: block; text-align: center;font-size: 20px; color: #6a737c; margin: 8px 0;">'+kFormatter(status.vote_num) +'</span>';
				//	$("#runoobvote-id-" + um_id + " .count").hide().after(_voteHtml);
				//}
				
			});
		}
	};
	if($('#comments').length && $('.upvotejs').length){
		$('.upvotejs').upvote({id: 20753, callback: callback});
	
		$.post(ajaxurl,{"action":"pinglun_zan","postid":20753},function(data){  
			$(data).each(function(key,value) {
				$("#runoobvote-id-" + value.commid + " .upvote").addClass(value.upvotejs_class);
				$("#runoobvote-id-" + value.commid + " .downvote").addClass(value.downvote_class);
				$("#runoobvote-id-" + value.commid + " .count").text(value.upvote_count);
			})
		},'json');
		
	}
	
	
});
function isBlank(str) {
    return (!str || /^\s*$/.test(str));
}
function kFormatter(num) {
	// return num;
    return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
}

</script>

<link rel="stylesheet" href="../0/qa.css?1.44">
<link rel="stylesheet" type="text/css" href="../0/simditor.min.css" />
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
		<div class="sidebar-box ">
				

<style>	
.responsive_ad1 { display:none; }
@media(min-width: 800px) { .responsive_ad1 {  display:block;margin:0 auto;} }
</style>
<div id="ad-336280" >

<script async src=""
     crossorigin="anonymous"></script>
<!-- 移动版 自动调整 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="1691338467"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
				</div>
		
	</div>
</div>
	

<!-- 右边栏 -->
<div class="fivecol last right-column">

<style>
.sidebar-tree .double-li {
    width:300px;
}
.sidebar-tree .double-li li {
    width: 44%;
    line-height: 1.5em;
    border-bottom: 1px solid #ccc;
    float: left;
    display: inline;
}
</style>

    
        <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here" style="margin: 0 auto;">
            <a href="javascript:void(0);" style="font-size: 16px; color:#64854c;font-weight:bold;"> <i class="fa fa-list" aria-hidden="true"></i> 分类导航</a>
        </div>
    <div class="sidebar-box sidebar-cate">
        
        <div class="sidebar-tree" >
            <ul><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> HTML / CSS</a><ul class="double-li"><li><a title="HTML 教程" href="../html/html-tutorial.html">HTML 教程</a></li><li><a title="HTML5 教程" href="../html/html5-intro.html">HTML5 教程</a></li><li><a title="CSS 教程" href="../css/css-tutorial.html">CSS 教程</a></li><li><a title="CSS3 教程" href="../css3/css3-tutorial.html">CSS3 教程</a></li><li><a title="Bootstrap3 教程" href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程</a></li><li><a title="Bootstrap4 教程" href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程</a></li><li><a title="Bootstrap5 教程" href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程</a></li><li><a title="Font Awesome 教程" href="../font-awesome/fontawesome-tutorial.html">Font Awesome 教程</a></li><li><a title="Foundation 教程" href="../foundation/foundation-tutorial.html">Foundation 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> JavaScript</a><ul class="double-li"><li><a title="JavaScript 教程" href="../js/js-tutorial.html">JavaScript 教程</a></li><li><a title="HTML DOM 教程" href="../htmldom/htmldom-tutorial.html">HTML DOM 教程</a></li><li><a title="jQuery 教程" href="../jquery/jquery-tutorial.html">jQuery 教程</a></li><li><a title="AngularJS 教程" href="../angularjs/angularjs-tutorial.html">AngularJS 教程</a></li><li><a title="AngularJS2 教程" href="../angularjs2/angularjs2-tutorial.html">AngularJS2 教程</a></li><li><a title="Vue.js 教程" href="../vue2/vue-tutorial.html">Vue.js 教程</a></li><li><a title="Vue3 教程" href="../vue3/vue3-tutorial.html">Vue3 教程</a></li><li><a title="React 教程" href="../react/react-tutorial.html">React 教程</a></li><li><a title="TypeScript 教程" href="../typescript/ts-tutorial.html">TypeScript 教程</a></li><li><a title="jQuery UI 教程" href="../jqueryui/jqueryui-tutorial.html">jQuery UI 教程</a></li><li><a title="jQuery EasyUI 教程" href="../jeasyui/jqueryeasyui-tutorial.html">jQuery EasyUI 教程</a></li><li><a title="Node.js 教程" href="../nodejs/nodejs-tutorial.html">Node.js 教程</a></li><li><a title="AJAX 教程" href="../ajax/ajax-tutorial.html">AJAX 教程</a></li><li><a title="JSON 教程" href="../json/json-tutorial.html">JSON 教程</a></li><li><a title="Echarts 教程" href="../echarts/echarts-tutorial.html">Echarts 教程</a></li><li><a title="Chart.js 教程" href="../chartjs/chartjs-tutorial.html">Chart.js 教程</a></li><li><a title="Highcharts 教程" href="../highcharts/highcharts-tutorial.html">Highcharts 教程</a></li><li><a title="Google 地图 教程" href="../googleapi/google-maps-basic.html">Google 地图 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 服务端</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="Python2.x 教程" href="../python/python-tutorial.html">Python2.x 教程</a></li><li><a title="Linux 教程" href="../linux/linux-tutorial.html">Linux 教程</a></li><li><a title="Docker 教程" href="../docker/docker-tutorial.html">Docker 教程</a></li><li><a title="Ruby 教程" href="../ruby/ruby-tutorial.html">Ruby 教程</a></li><li><a title="Java 教程" href="../java/java-tutorial.html">Java 教程</a></li><li><a title="C 教程" href="../c/c-tutorial.html">C 教程</a></li><li><a title="C++ 教程" href="../cplusplus/cpp-tutorial.html">C++ 教程</a></li><li><a title="Perl 教程" href="../perl/perl-tutorial.html">Perl 教程</a></li><li><a title="Servlet 教程" href="../servlet/servlet-tutorial.html">Servlet 教程</a></li><li><a title="JSP 教程" href="../jsp/jsp-tutorial.html">JSP 教程</a></li><li><a title="Lua 教程" href="../lua/lua-tutorial.html">Lua 教程</a></li><li><a title="Rust 教程" href="../rust/rust-tutorial.html">Rust 教程</a></li><li><a title="Scala 教程" href="../scala/scala-tutorial.html">Scala 教程</a></li><li><a title="Go 教程" href="../go/go-tutorial.html">Go 教程</a></li><li><a title="PHP 教程" href="../php/php-tutorial.html">PHP 教程</a></li><li><a title="数据结构与算法" href="../data-structures/data-structures-tutorial.html">数据结构与算法</a></li><li><a title="Django 教程" href="../django/django-tutorial.html">Django 教程</a></li><li><a title="Zookeeper 教程" href="../w3cnote/zookeeper-tutorial.html">Zookeeper 教程</a></li><li><a title="设计模式" href="../design-pattern/design-pattern-tutorial.html">设计模式</a></li><li><a title="正则表达式" href="../regexp/regexp-tutorial.html">正则表达式</a></li><li><a title="Maven 教程" href="../maven/maven-tutorial.html">Maven 教程</a></li><li><a title="Verilog 教程" href="../w3cnote/verilog-tutorial.html">Verilog 教程</a></li><li><a title="ASP 教程" href="../asp/asp-tutorial.html">ASP 教程</a></li><li><a title="AppML 教程" href="../appml/appml-tutorial.html">AppML 教程</a></li><li><a title="VBScript 教程" href="../vbscript/vbscript-tutorial.html">VBScript 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据库</a><ul class="double-li"><li><a title="SQL 教程" href="../sql/sql-tutorial.html">SQL 教程</a></li><li><a title="MySQL 教程" href="../mysql/mysql-tutorial.html">MySQL 教程</a></li><li><a title="PostgreSQL 教程" href="../postgresql/postgresql-tutorial.html">PostgreSQL 教程</a></li><li><a title="SQLite 教程" href="../sqlite/sqlite-tutorial.html">SQLite 教程</a></li><li><a title="MongoDB 教程" href="../mongodb/mongodb-tutorial.html">MongoDB 教程</a></li><li><a title="Redis 教程" href="../redis/redis-tutorial.html">Redis 教程</a></li><li><a title="Memcached 教程" href="../Memcached/Memcached-tutorial.html">Memcached 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据分析</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="NumPy 教程" href="../numpy/numpy-tutorial.html">NumPy 教程</a></li><li><a title="Pandas 教程" href="../pandas/pandas-tutorial.html">Pandas 教程</a></li><li><a title="Matplotlib 教程" href="../matplotlib/matplotlib-tutorial.html">Matplotlib 教程</a></li><li><a title="Scipy 教程" href="../scipy/scipy-tutorial.html">Scipy 教程</a></li><li><a title="R 教程" href="../r/r-tutorial.html">R 教程</a></li><li><a title="Julia 教程" href="../julia/julia-tutorial.html">Julia 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 移动端</a><ul class="double-li"><li><a title="Android 教程" href="../w3cnote/android-tutorial-intro.html">Android 教程</a></li><li><a title="Swift 教程" href="../swift/swift-tutorial.html">Swift 教程</a></li><li><a title="jQuery Mobile 教程" href="../jquerymobile/jquerymobile-tutorial.html">jQuery Mobile 教程</a></li><li><a title="ionic 教程" href="../ionic/ionic-tutorial.html">ionic 教程</a></li><li><a title="Kotlin 教程" href="../kotlin/kotlin-tutorial.html">Kotlin 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> XML 教程</a><ul class="double-li"><li><a title="XML 教程" href="../xml/xml-tutorial.html">XML 教程</a></li><li><a title="DTD 教程" href="../dtd/dtd-tutorial.html">DTD 教程</a></li><li><a title="XML DOM 教程" href="../dom/dom-tutorial.html">XML DOM 教程</a></li><li><a title="XSLT 教程" href="../xsl/xsl-tutorial.html">XSLT 教程</a></li><li><a title="XPath 教程" href="../xpath/xpath-tutorial.html">XPath 教程</a></li><li><a title="XQuery 教程" href="../xquery/xquery-tutorial.html">XQuery 教程</a></li><li><a title="XLink 教程" href="../xlink/xlink-tutorial.html">XLink 教程</a></li><li><a title="XPointer 教程" href="../xlink/xlink-tutorial.html">XPointer 教程</a></li><li><a title="XML Schema 教程" href="../schema/schema-tutorial.html">XML Schema 教程</a></li><li><a title="XSL-FO 教程" href="../xslfo/xslfo-tutorial.html">XSL-FO 教程</a></li><li><a title="SVG 教程" href="../svg/svg-tutorial.html">SVG 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> ASP.NET</a><ul class="double-li"><li><a title="ASP.NET 教程" href="../aspnet/aspnet-tutorial.html">ASP.NET 教程</a></li><li><a title="C# 教程" href="../csharp/csharp-tutorial.html">C# 教程</a></li><li><a title="Web Pages 教程" href="../aspnet/webpages-intro.html">Web Pages 教程</a></li><li><a title="Razor 教程" href="../aspnet/razor-intro.html">Razor 教程</a></li><li><a title="MVC 教程" href="../aspnet/mvc-intro.html">MVC 教程</a></li><li><a title="Web Forms 教程" href="../aspnet/aspnet-intro.html">Web Forms 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> Web Service</a><ul class="double-li"><li><a title="Web Service 教程" href="../webservices/webservices-tutorial.html">Web Service 教程</a></li><li><a title="WSDL 教程" href="../wsdl/wsdl-tutorial.html">WSDL 教程</a></li><li><a title="SOAP 教程" href="../soap/soap-tutorial.html">SOAP 教程</a></li><li><a title="RSS 教程" href="../rss/rss-tutorial.html">RSS 教程</a></li><li><a title="RDF 教程" href="../rdf/rdf-tutorial.html">RDF 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 开发工具</a><ul class="double-li"><li><a title="Eclipse 教程" href="../eclipse/eclipse-tutorial.html">Eclipse 教程</a></li><li><a title="Git 教程" href="../git/git-tutorial.html">Git 教程</a></li><li><a title="Svn 教程" href="../svn/svn-tutorial.html">Svn 教程</a></li><li><a title="Markdown 教程" href="../markdown/md-tutorial.html">Markdown 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 网站建设</a><ul class="double-li"><li><a title="HTTP 教程" href="../http/http-tutorial.html">HTTP 教程</a></li><li><a title="网站建设指南" href="../web/web-buildingprimer.html">网站建设指南</a></li><li><a title="浏览器信息" href="../browsers/browser-information.html">浏览器信息</a></li><li><a title="网站主机教程" href="../hosting/hosting-tutorial.html">网站主机教程</a></li><li><a title="TCP/IP 教程" href="../tcpip/tcpip-tutorial.html">TCP/IP 教程</a></li><li><a title="W3C 教程" href="../w3c/w3c-tutorial.html">W3C 教程</a></li><li><a title="网站品质" href="../quality/quality-tutorial.html">网站品质</a></li></ul></li></ul>            </div>
    
    </div>
    </div>
    <br>
    
    <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here">
            <a href="javascript:void(0);">Advertisement</a>
        </div>
        <div class="re-600160" id="sidebar-right-re">
                <script async src=""></script>
        <!-- 侧栏1 -->
        <ins class="adsbygoogle"
             style="display:inline-block;width:160px;height:600px"
             data-ad-client="ca-pub-5751451760833794"
             data-ad-slot="4106274865"></ins>
        <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
                </div>
    </div>
</div></div>

</div>

<script>
var aid = 20753;
function coll() {
	$.post( '/wp-content/themes/runoob/option/user/userinfo.php', {aid:aid, action:"collarticle", opt:'add'},function( data ) {
		if(data.error==0) {
			$("#content").find("h1:first").find("a").attr("href","javascript:void(0);");
			$("#content").find("h1:first").find("img").attr("src","http://www.runoob.com/wp-content/themes/runoob/assets/img/coll2.png").css({width:32+"px",height:32+"px"});
		}
		alert(data.msg);
	},'json');
}
</script>


<!-- 反馈对话框开始 -->
<script src=""></script>
<link rel="stylesheet" href="../0/feedback.css?1.0" />
<script type="text/javascript">
$.feedback({
    ajaxURL: '/feedback/runoob_feedback.php',
	html2canvasURL: '/wp-content/themes/runoob/assets/feedback/stable/2.0/html2canvas.js',
	onClose: function () {
         window.location.reload();
    }
});
</script>
<!-- 反馈对话框结束 -->
<button class="feedback-btn feedback-btn-gray">反馈/建议</button>
<!-- 底部 -->
<div id="footer" class="mar-t50">
   <div class="runoob-block">
    <div class="runoob cf">
     <dl>
      <dt>
       在线实例
      </dt>
      <dd>
       &middot;<a target="_blank" href="../html/html-examples.html">HTML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../css/css-examples.html">CSS 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../js/js-examples.html">JavaScript 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../ajx/ajax-examples.html">Ajax 实例</a>
      </dd>
       <dd>
       &middot;<a target="_blank" href="../jquery/jquery-examples.html">jQuery 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../xml/xml-examples.html">XML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../java/java-examples.html">Java 实例</a>
      </dd>
     
     </dl>
     <dl>
      <dt>
      字符集&工具
      </dt>
      <dd>
       &middot; <a target="_blank" href="../charsets/html-charsets.html">HTML 字符集设置</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-ascii.html">HTML ASCII 字符集</a>
      </dd>
     <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6939/">JS 混淆/加密</a>
      </dd> 
      <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6232/">PNG/JPEG 图片压缩</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-colorpicker.html">HTML 拾色器</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/53">JSON 格式化工具</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/6680/">随机数生成器</a>
      </dd>
     </dl>
     <dl>
      <dt>
       最新更新
      </dt>
                   <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imread.html" title="Matplotlib imread() 方法">Matplotlib imre...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imsave.html" title="Matplotlib imsave() 方法">Matplotlib imsa...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imshow.html" title="Matplotlib imshow() 方法">Matplotlib imsh...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-hist.html" title="Matplotlib 直方图">Matplotlib 直方图</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-func-object.html" title="Python object() 函数">Python object()...</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-ai-draw.html" title="Python AI 绘画">Python AI 绘画</a>
      </dd>
              <dd>
       &middot;
      <a href="../w3cnote/cursor-editor.html" title="神辅助 Cursor 编辑器，加入 GPT-4 让编码更轻松！">神辅助 Cursor ...</a>
      </dd>
             </dl>
     <dl>
      <dt>
       站点信息
      </dt>
      <dd>
       &middot;
       <a target="_blank" href="mailto:admin@runoob.com" rel="external nofollow">意见反馈</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../disclaimer">免责声明</a>
       </dd>
      <dd>
       &middot;
       <a target="_blank" href="../aboutus">关于我们</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../archives">文章归档</a>
      </dd>
    
     </dl>
    
     <div class="search-share">
      <div class="app-download">
        <div>
         <strong>关注微信</strong>
        </div>
      </div>
      <div class="share">
      <img width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png" />
       </div>
     </div>
     
    </div>
   </div>
   <div class="w-1000 copyright">
     Copyright &copy; 2013-2023    <strong><a href="../" target="_blank">菜鸟教程</a></strong>&nbsp;
    <strong><a href="../" target="_blank">runoob.com</a></strong> All Rights Reserved. 备案号：<a target="_blank" rel="nofollow" href="https://beian.miit.gov.cn/">闽ICP备15012807号-1</a>
   </div>
  </div>
  <div class="fixed-btn">
    <a class="go-top" href="javascript:void(0)" title="返回顶部"> <i class="fa fa-angle-up"></i></a>
    <a class="qrcode"  href="javascript:void(0)" title="关注我们"><i class="fa fa-qrcode"></i></a>
    <a class="writer" style="display:none" href="javascript:void(0)"   title="标记/收藏"><i class="fa fa-star" aria-hidden="true"></i></a>
    <!-- qrcode modal -->
    <div id="bottom-qrcode" class="modal panel-modal hide fade in">
      <h4>微信关注</h4>
      <div class="panel-body"><img alt="微信关注" width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png"></div> 
    </div>
  </div>

 <div style="display:none;">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-84264393-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-84264393-2');
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?3eec0b7da6548cf07db3bc477ea905ee";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</div>
<script>
window.jsui={
    www: 'https://www.runoob.com',
    uri: 'https://www.runoob.com/wp-content/themes/runoob'
};
</script>

<script src=""></script>
<script src=""></script>

</body>
</html>